package com.sxfq.loansupermarket.backsystem.modular.IntegralMall.service.Impl;

import com.sxfq.loansupermarket.backsystem.core.shiro.ShiroKit;
import com.sxfq.loansupermarket.backsystem.modular.IntegralMall.entity.PointRewordInfo;
import com.sxfq.loansupermarket.backsystem.modular.IntegralMall.service.IGetCacheListService;
import com.sxfq.loansupermarket.backsystem.modular.arrival.entity.ScoreDealInfo;
import com.sxfq.loansupermarket.backsystem.modular.base.SqlMapper;
import com.sxfq.loansupermarket.backsystem.modular.basicData.entity.VipLevelInfo;
import com.sxfq.loansupermarket.backsystem.modular.doctorLooked.entity.DoctorDiagnosisInfo;
import com.sxfq.loansupermarket.backsystem.modular.weixin.entity.MedicalAdviceInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Service
@Transactional
public class GetCacheListServiceImpl implements IGetCacheListService {
    @Autowired
    private SqlMapper sqlMapper;

    public List<DoctorDiagnosisInfo> getDoctorAdviceList(){
        String sql = "select id ,doctor_advice,finnally_time,doctor_id as doctor from case_info a " +
                " where reservations_id='" + ShiroKit.getSessionAttr("reservationsId") + "' order by finnally_time";
        List<DoctorDiagnosisInfo> doctorAdviceList = sqlMapper.selectList(sql, DoctorDiagnosisInfo.class);
        return doctorAdviceList;
    }

    public List<ScoreDealInfo> getScoreRecord(){
        String sql = "select id,score_balance,add_time,remarks from score_deal a " +
                " where reservations_id='" + ShiroKit.getSessionAttr("reservationsId") + "' and score_balance!=0 order by add_time desc";
        List<ScoreDealInfo> slist = sqlMapper.selectList(sql, ScoreDealInfo.class);
        return slist;
    }

    public MedicalAdviceInfo getMedicalAdviceInfo(String medicalAdviceTitle){
        String sql = "select * from medical_advice_info where medical_advice_title='" + medicalAdviceTitle + "'";
        MedicalAdviceInfo medicalAdviceInfo = sqlMapper.selectOne(sql, MedicalAdviceInfo.class);
        return medicalAdviceInfo;
    }

    public VipLevelInfo getIntegralRule(){
        String sql = "select integral_rule as integralRule,area from integral_rule_info limit 1";
        VipLevelInfo info = sqlMapper.selectOne(sql, VipLevelInfo.class);
        return info;
    }

    public List<PointRewordInfo> getPointRewordInfoList() {
        String sql = "select left(b.create_time,19) as createTime,a.id as id,a.reservations_id as reservationsId,b.product_name as productName ," +
                " if(a.status=1,'未兑换','已兑换') as status,a.code " +
                " from point_conversion_info a left join point_reword_info b on a.product_id=b.id " +
                "where a.reservations_id='" + ShiroKit.getSessionAttr("reservationsId") + "' order by b.create_time desc";
        List<PointRewordInfo> list = sqlMapper.selectList(sql, PointRewordInfo.class);
        return list;
    }

    public PointRewordInfo getPointRewordInfo(String id) {
        String sql = "select a.id,a.product_id,a.image_path,a.num,a.mainFigure,b.area " +
                "from point_reword_iconinfo a left join point_reword_info b on a.product_id=b.id where product_id='"+id+"' ";
        List<PointRewordInfo> infoIcon = sqlMapper.selectList(sql, PointRewordInfo.class);
        String pointSql = "select * from point_reword_info where id='" + id + "' ";
        PointRewordInfo info = sqlMapper.selectOne(pointSql, PointRewordInfo.class);
        info.setPointRewordIconInfo(infoIcon);
        return info;
    }

    public PointRewordInfo getIdCodeById(String id) {
        String codeSql = "select id,code from point_conversion_info where id='" + id + "'";
        PointRewordInfo pointRewordInfo = sqlMapper.selectOne(codeSql, PointRewordInfo.class);
        return pointRewordInfo;
    }
}